<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * form组件的父类,提供默认的属性,和方法
<span class='line'>  3</span>  * @param options 参见{@link #getOptions}返回的对象
<span class='line'>  4</span>  * @constructor
<span class='line'>  5</span>  */</span><span class="WHIT">
<span class='line'>  6</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">FDComponent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>  7</span> </span><span class="WHIT">	</span><span class="NAME">FDLib.implement</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="NAME">FDControl</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>  8</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'>  9</span> </span><span class="WHIT">	</span><span class="NAME">this.options</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">FDLib.util.apply</span><span class="PUNC">(</span><span class="NAME">this.getOptions</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 10</span> 
<span class='line'> 11</span> </span><span class="WHIT">	</span><span class="NAME">this.contentDoms</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.refreshContent</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="WHIT">	</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">FDLib.util.isArray</span><span class="PUNC">(</span><span class="NAME">this.contentDoms</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="WHIT">		</span><span class="NAME">this.contentDoms</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">this.contentDoms</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 16</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT">	</span><span class="NAME">this.render</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="WHIT">	</span><span class="NAME">this.initEvent</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">			</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="WHIT">	</span><span class="NAME">this.setBounds</span><span class="PUNC">(</span><span class="NAME">this.options.width</span><span class="PUNC">,</span><span class="NAME">this.options.height</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="NAME">FDComponent.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="COMM">/**
<span class='line'> 26</span>  * 获取组件的默认属性
<span class='line'> 27</span>    @return &lt;pre>&lt;code>返回json数据类型
<span class='line'> 28</span> {
<span class='line'> 29</span> 	domId:null // 定位的节点ID
<span class='line'> 30</span> 	,label:"" // 控件前面要显示的文字
<span class='line'> 31</span> 	,labelAlign:'right' // label水平对齐方式
<span class='line'> 32</span> 	,labelValign:'middle' // label垂直对齐方式
<span class='line'> 33</span> 	,name:"" // 控件的name
<span class='line'> 34</span> 	,width:"" // 控件的宽,如'120px'
<span class='line'> 35</span> 	,height:"" // 控件的高,如'30px'
<span class='line'> 36</span> 	,validates:[] // 验证类
<span class='line'> 37</span> 	,renderable:true // 是否画出控件,false则不画出,这样在HTML中就不显示
<span class='line'> 38</span> }&lt;/code>&lt;/pre>
<span class='line'> 39</span>  */</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">	</span><span class="NAME">getOptions</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT">			</span><span class="NAME">domId</span><span class="PUNC">:</span><span class="KEYW">null</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">label</span><span class="PUNC">:</span><span class="STRN">""</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">labelAlign</span><span class="PUNC">:</span><span class="STRN">'right'</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">labelValign</span><span class="PUNC">:</span><span class="STRN">'middle'</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">name</span><span class="PUNC">:</span><span class="STRN">""</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">width</span><span class="PUNC">:</span><span class="STRN">""</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">height</span><span class="PUNC">:</span><span class="STRN">""</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">validates</span><span class="PUNC">:</span><span class="PUNC">[</span><span class="PUNC">]</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">			</span><span class="PUNC">,</span><span class="NAME">renderable</span><span class="PUNC">:</span><span class="KEYW">true</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 54</span> 	 * 初始化事件
<span class='line'> 55</span> 	 */</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">initEvent</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 58</span> 	 * 将控件渲染到页面上,如果指定domId,则渲染到对应的domId中
<span class='line'> 59</span> 	 * 否则渲染到body中
<span class='line'> 60</span> 	 * @param domId
<span class='line'> 61</span> 	 */</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">render</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">domId</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">domId</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">FDLib.util.isString</span><span class="PUNC">(</span><span class="NAME">domId</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">			</span><span class="NAME">this.options.domId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">domId</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">		</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">desDom</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">FDLib.getEl</span><span class="PUNC">(</span><span class="NAME">this.options.domId</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">document.body</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">		</span><span class="NAME">this.renderToDom</span><span class="PUNC">(</span><span class="NAME">desDom</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 71</span> 	 * 将控件渲染到指定dom对象中
<span class='line'> 72</span> 	 * @param dom DOM对象
<span class='line'> 73</span> 	 */</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">renderToDom</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">desDom</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">		</span><span class="NAME">FDLib.util.each</span><span class="PUNC">(</span><span class="NAME">this.contentDoms</span><span class="PUNC">,</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">			</span><span class="NAME">desDom.appendChild</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 80</span> 	 * 初始化控件内容
<span class='line'> 81</span> 	 */</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">initContent</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">		</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">contentDom</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.buildContent</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">		</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">FDLib.util.isArray</span><span class="PUNC">(</span><span class="NAME">contentDom</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">			</span><span class="NAME">FDLib.util.each</span><span class="PUNC">(</span><span class="NAME">contentDom</span><span class="PUNC">,</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">				</span><span class="NAME">this.outerDiv.appendChild</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="KEYW">else</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">			</span><span class="NAME">this.outerDiv.appendChild</span><span class="PUNC">(</span><span class="NAME">contentDom</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 94</span> 	 * 刷新控件内容
<span class='line'> 95</span> 	 */</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">refreshContent</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">		</span><span class="NAME">this.contentDoms</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.buildContent</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT">		</span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">FDLib.util.isArray</span><span class="PUNC">(</span><span class="NAME">this.contentDoms</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">			</span><span class="NAME">this.contentDoms</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="NAME">this.contentDoms</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">		</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.contentDoms</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'>106</span> 	 * 构建内容
<span class='line'>107</span> 	 * @param 返回DOM对象
<span class='line'>108</span> 	 */</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">buildContent</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">		</span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Error</span><span class="PUNC">(</span><span class="STRN">'必须重写FDComponent.buildContent()方法'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">	</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'>113</span> 	 * 显示控件
<span class='line'>114</span> 	 */</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">show</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">		</span><span class="NAME">FDLib.util.each</span><span class="PUNC">(</span><span class="NAME">this.contentDoms</span><span class="PUNC">,</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">			</span><span class="NAME">dom.style.display</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"block"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'>121</span> 	 * 隐藏控件
<span class='line'>122</span> 	 */</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">	</span><span class="PUNC">,</span><span class="NAME">hide</span><span class="PUNC">:</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">		</span><span class="NAME">FDLib.util.each</span><span class="PUNC">(</span><span class="NAME">this.contentDoms</span><span class="PUNC">,</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dom</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">			</span><span class="NAME">dom.style.display</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"none"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>128</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> 
<span class='line'>130</span> </span></pre></body></html>